feat(args): add --body-file flag to load changelog body from a file#1563
Open
SarthakB11 wants to merge 1 commit into
Open
feat(args): add --body-file flag to load changelog body from a file#1563SarthakB11 wants to merge 1 commit into
SarthakB11 wants to merge 1 commit into
Conversation
Reading a multiline template via `--body "$(cat template.tera)"` breaks on newlines (or collapses to one line), as reported in orhun#1558. Templates that start with directives like `{% raw %}` are especially prone to this. Add a sibling `--body-file <PATH>` argument that reads the template from a file. It mirrors `--from-context` in shape: tilde expansion via `Opt::parse_dir`, env var `GIT_CLIFF_TEMPLATE_FILE`, and `PathBuf` typing. `--body` and `--body-file` are marked `conflicts_with` so only one may be set at a time. Closes orhun#1558 Signed-off-by: SarthakB11 <sarthak.bhardwaj21b@iiitg.ac.in>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
--body-file <PATH>argument that loads the changelog body template from a file, as an alternative to the inline--body <TEMPLATE>argument.--body-file <PATH>(also configurable via theGIT_CLIFF_TEMPLATE_FILEenvironment variable).~) expansion via the existingOpt::parse_dirhelper, consistent with--from-contextand other path arguments.--bodyand--body-fileare markedconflicts_withso only one may be set at a time.website/docs/usage/args.mdandwebsite/docs/usage/examples.md. The man page and shell completions pick up the new argument automatically from the clap definition.Motivation and Context
Passing a multiline template inline via
--body "$(cat template.tera)"breaks on newlines, as reported in #1558. Templates often start with directives like{% raw %}, which makes the breakage particularly confusing. A dedicated--body-fileargument lets users keep their template in a file:Closes #1558
How Has This Been Tested?
cargo build -p git-cliffcleancargo test -p git-cliff --liball 7 tests pass, including two new ones:body_file_is_parsed_as_pathverifies--body-fileparses into aPathBufand does not setbodybody_and_body_file_conflictverifies clap rejects setting both flags withArgumentConflictcargo clippy -p git-cliff --tests -- -D warningsno warningscargo +nightly fmt --all -- --checkcleantemplate.terastarting with{% raw %}and confirmed the full file content was loaded into the changelog template (the case the issue reports as broken). The conflict check also fires at the CLI: passing both--bodyand--body-fileexits witherror: the argument '--body <TEMPLATE>' cannot be used with '--body-file <PATH>'.Types of Changes
Checklist:
cargo +nightly fmt --allcargo clippy --tests --verbose -- -D warningscargo test